package com.lms.admin.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lms.admin.base.mapper.SysRoleMenuMapper;
import com.lms.admin.base.service.ISysRoleMenuService;
import com.lms.common.entity.SysRoleMenu;
import com.lms.common.web.service.impl.WrapperServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SysRoleMenuServiceImpl extends WrapperServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {
    @Override
    public IPage<?> queryMapper(Page<SysRoleMenu> page, Map<String, Object> p) {
        return null;
    }

    @Override
    public List<SysRoleMenu> getRoleByUserId(Long menuId) {
        QueryWrapper<SysRoleMenu> params = new QueryWrapper<>();
        params.eq("menu_id", menuId);
        return this.baseMapper.selectList(params);
    }

    @Override
    public void removeByMenuId(Long menuId) {
        QueryWrapper<SysRoleMenu> params = new QueryWrapper<>();
        params.eq("menu_id", menuId);
        // 先删除关联角色
        this.baseMapper.delete(params);
    }

    @Override
    public void removeByRoleId(Long roleId) {
        QueryWrapper<SysRoleMenu> params = new QueryWrapper<>();
        params.eq("role_id", roleId);
        // 先删除关联角色
        this.baseMapper.delete(params);
    }
}
